package com.wy.panda.config;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.wy.panda.common.bean.converter.PageResultConverter;
import com.wy.panda.common.util.BeanUtils;

import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.converter.ConverterFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;

/**
 * Orika配置
 * 
 * @author wangyuan
 * @since 2020-9-7 23:22:32
 *
 */
@Configuration
public class OrikaConfig {

    @Bean
    public MapperFactory mapperFactory() {
        return new DefaultMapperFactory.Builder().build();
    }
    
    @Autowired
    private MapperFactory mapperFactory;
    
    @PostConstruct
    public void init() {
        ConverterFactory converterFactory = mapperFactory.getConverterFactory();
        converterFactory.registerConverter(new PageResultConverter<Object, Object>());
        
        BeanUtils.init(mapperFactory);
    }
}
